using HIDInterface;
namespace WinFormsApp1
{

    public partial class Form1 : Form
    {
        Hid_Device_Info hid_device_info;
        HIDDevice hid_device = null;

        public Form1()
        {
            InitializeComponent();
        }

        private void hIDToolStripMenuItem_Click(object sender, EventArgs e)
        {
            HIDDevice.interfaceDetails[] devices = HIDDevice.getConnectedDevices();
            List<Hid_Device_Info> infos = new List<Hid_Device_Info>();
            foreach (HIDDevice.interfaceDetails device in devices)
            {
                Hid_Device_Info info = new Hid_Device_Info();
                info.VID = device.VID.ToString("X");
                info.PID = device.PID.ToString("X");
                info.PATH = device.devicePath;
                infos.Add(info);
            }
            Form2 form = new Form2();
            form.set_list_source(infos);

            DialogResult result = form.ShowDialog(this);
            if (result == DialogResult.OK)
            {
                hid_device_info = form.get_select_device_info();
                hid_device = new HIDDevice(hid_device_info.PATH, true);
                hid_device.dataReceived += new HIDDevice.dataReceivedEvent(hid_dataReceived);
            }

        }

        public void hid_dataReceived(byte[] message)
        {
            //Do something with the data here...
            string t = message.ToString();
            richTextBox1.AppendText(t);
        }
    }



    public class Hid_Device_Info
    {
        private string vid = "";
        private string pid = "";
        private string path = "";

        public string PATH
        { get { return path; } set { path = value; } }

        public string VID
        { get { return vid; } set { vid = value; } }
        public string PID
        { get { return pid; } set { pid = value; } }

    }
}